import ajax from './ajax.js'

let form = document.querySelector('#form');
let usernameInp = document.getElementsByName('username')[0];
let pwdInp = document.getElementsByName('pwd')[0];
let tip = document.querySelector('.tip')

form.onsubmit = function(e){
    e.preventDefault();
    console.log('123');

    // 登录 - 登录接口
    ajax.post('http://localhost/login',`username=${usernameInp.value}&pwd=${pwdInp.value}`).then( ({code,message,key})=>{
        // console.log(data);
       
        console.log(code);

        if(code ===200){
            console.log("登录成功");

            // 存储数据
            sessionStorage.setItem('login',key)

            window.location.href = './list.html';
        }else{
            console.log(message);
            tip.innerHTML = message;
        }
    });

}
